//
//  HSBC_Cities.m
//  Bracelet
//
//  Created by Jayce on 15/3/10.
//  Copyright (c) 2015年 jing zhao. All rights reserved.
//

#import "HSBC_Cities.h"
#import "APIHSBCCities.h"

@interface HSBC_Cities ()
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *ui_activityView;

@end

@implementation HSBC_Cities

-(void)initWithType:(NSString*)type
{
    [self.ui_activityView startAnimating];
//    [self updateNetwork];
    self.ui_webView.scrollView.scrollEnabled = NO;
}


-(void)updateNetwork
{
    UIRefreshTableView *refresh = (UIRefreshTableView*)self.superview;
    
    [APIHSBCCities getHSBCDataSuccess:^(APIHSBCCities *mycity) {
        //self.targetedCitiesCount.text = mycity.strCityNum;
        [self setTargetedCitiesCountLable:mycity.strCityNum];
        [self.ui_webView loadHTMLString:mycity.strHtml baseURL:nil];
        [self.ui_activityView stopAnimating];
         [refresh endRefreshData];
        
    } failure:^(NSError *error) {
            [self.ui_activityView stopAnimating];
           [refresh endRefreshData];
    }];
}

- (void)setTargetedCitiesCountLable:(NSString *)cityStr{
    
    NSString *citiesStr = [NSString stringWithFormat:@"%@ cities",cityStr];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ (in red) have achieved the current target", citiesStr]];
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Univers Next for HSBC W01 Rg" size:12.0] range:NSMakeRange(0, [str length])];
    
    NSRange range = [[str mutableString] rangeOfString:@"red"];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:110/255.0 green:110/255.0 blue:110/255.0 alpha:1.0] range:NSMakeRange(0, [str length])];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:219/255.0 green:0/255.0 blue:17/255.0 alpha:1.0] range:range];
    
    self.targetedCitiesCount.attributedText = str;

}


@end
